import argparse
import random

def generate_data(data_type, size, seed=None):
    if seed is not None:
        random.seed(seed)
    
    if data_type == "random":
        return [random.randint(0, 10000) for _ in range(size)]
    elif data_type == "sorted":
        return list(range(size))
    elif data_type == "reverse":
        return list(range(size, 0, -1))
    elif data_type == "uniform":
        return [42] * size
    else:
        raise ValueError("Invalid data type")

def save_to_file(data, filename):
    with open(filename, 'w') as f:
        f.write(' '.join(map(str, data)))

def main():
    parser = argparse.ArgumentParser(description='Generate test datasets for sorting algorithms')
    parser.add_argument('--type', choices=['random', 'sorted', 'reverse', 'uniform'], required=True,
                        help='Type of dataset to generate')
    parser.add_argument('--size', type=int, default=1000, help='Size of the dataset')
    parser.add_argument('--seed', type=int, help='Random seed for reproducibility')
    parser.add_argument('--output', help='Output filename')
    
    args = parser.parse_args()
    
    if args.output is None:
        args.output = f"{args.type}_{args.size}.txt"
    
    data = generate_data(args.type, args.size, args.seed)
    save_to_file(data, args.output)
    print(f"Generated {args.type} dataset ({args.size} elements) saved to {args.output}")

if __name__ == "__main__":
    main()